package com.lin.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Advice {
    @Pointcut("execution(* com.lin.service.Impl.*.*(..))")
    public void pc(){} // 定义切入点, 空方法体作为承载体, 表示...service.Impl包下的所有方法都会被切入(增强)

    /*@Before("pc()") // 使用Advice.pc()或pc()使用切入点
    public void before() {
        System.out.println("before advice...");
    }*/

    /*@After("pc()")
    public void after() {
        System.out.println("after advice...");
    }*/

    @Around("pc()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before advice...");
        Object proceed = pjp.proceed();
        System.out.println("around after advice...");
        return proceed;
    }

    @AfterThrowing(pointcut = "pc()", throwing = "throwable")
    public void afterThrowing(Throwable throwable) {
        System.out.println("afterThrowing advice...Exception!!!");
    }

    @AfterReturning("pc()")
    public void afterReturning() {
        System.out.println("afterReturning advice...");
    }

}
